package wo.xsys.controller;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.support.SessionStatus;

import wo.common.exception.WoResultCode;
import wo.xsys.vo.WoMenu;

@Controller
@RequestMapping(value="/")
// @SessionAttributes(names={SysConstant.SESSION_USER})
public class HomeController {
	private final static Logger LOG = LogManager.getLogger(HomeController.class);
	
	/**
	 * @param map request中所有键值对，和session中部分键值对：@SessionAttributes中的所有key及值
	 * @return
	 */
	@RequestMapping (value="/")
	public String toHome (Map<String, Object> map) {
		String msg = "欢迎您！";
		map.put("woWelcomeMsg", msg);
		return "main";
	}
	
	/**
     * ExtJs使用，当获取顶级菜单时，传入的request中的值
     */
    private final static String ROOT = "woMenuRoot";
    
	@RequestMapping(value = "/getChildren")
	@ResponseBody
    public List<WoMenu> getChildren(String parentId) {
		List<WoMenu> menus = new ArrayList<WoMenu>();
    	if (ROOT.equals(parentId)) {
    		parentId = null;
        	menus.add(new WoMenu("1", "系统管理", "00", null, false, true));
    	} else {
    		menus.add(new WoMenu("2", "菜单", "0010", "XsysMenuGrid", true, false));
    		menus.add(new WoMenu("3", "角色", "0020", "XsysRoleGrid", true, false));
    		menus.add(new WoMenu("4", "用户", "0030", "XsysUserGrid", true, false));
    		menus.add(new WoMenu("5", "数据字典", "0040", "XsysDictionaryGrid", true, false));
    	}
        return menus;
    }
	
	@RequestMapping(value = "authentication", produces = "application/json")
	@ResponseBody
	public WoResultCode authenticate (String user, String password, Map<String, Object> map) {
		return WoResultCode.getSuccessCode();
	}
	
	@RequestMapping(value = "logout", produces = "application/json")
	@ResponseBody
	public WoResultCode logout (Map<String, Object> map, SessionStatus sessionStatus) {
		return WoResultCode.getSuccessCode();
	}
}
